﻿using System;
using System.Security.Principal;
using Netkk.Common;

namespace Netkk.Library.Auth
{
    public class CustomPrincipal : IPrincipal
    {
        public IIdentity Identity
        {
            get;
            private set;
        }

        public CustomPrincipal(IIdentity identity)
        {
            Identity = identity;
        }

        public bool IsInRole(Roles role)
        {
            if (((CustomIdentity)Identity).User == null)
            {
                return false;
            }
            return role == ((CustomIdentity)Identity).User.Role.Role;
        }

        public bool IsInRole(string role)
        {
            return IsInRole(role.ToOrDefault<Roles>());
        }
    }

}